package com.itranswarp.learnjava;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;

/**
 * Learn Java from https://www.liaoxuefeng.com/
 * 
 * @author liaoxuefeng
 */
public class Main {
	/**
	 * @Method  :   main
	 * @Time    :   2021/6/16 6:28 下午
	 * @Author  :   Zhang Hong
	 * @Version :   1.0
	 * @Contact :   zh224635@163.com
	 * @Desc    :   TODO      给定两个字符串, 判断某一字符串是否为另一字符串的子串.
	 **/


	public static void main(String[] args) throws Exception {
		String fatherStr = "toboornottobe";
		String sonStr = "bo";
		System.out.println(judgeString(sonStr, fatherStr));
	}
	/**
	 * @File    :   Main
	 * @Time    :   2021/6/16 6:29 下午
	 * @Author  :   Zhang Hong
	 * @Version :   1.0
	 * @Contact :   zh224635@163.com
	 * @Desc    :   TODO    暴力穷举法 双重for循环, 对比字符内容
	 **/

	public static boolean judgeString(String sonStr , String fatherStr) {
		boolean flag = true;
		for (int i = 0; i < fatherStr.length() - sonStr.length(); i++) {
			//第一重循环, 循环次数 F串长度 - S串长度.循环完成后,仍无法匹配, 返回false
			if (fatherStr.charAt(i) == sonStr.charAt(0)){
				//匹配成功后,进入下一重循环, 循环次数为 S串长度, 当遇到不匹配的时候, 返回false
				for (int j = 0; j < sonStr.length() ; j++) {
					if (fatherStr.charAt(i+j) != sonStr.charAt(j)){
						return false;
					}
					
				}
			}
			flag = false;
		}
		return flag;
	}
}
